package com.gpnu.crm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageInfo;
import com.gpnu.crm.domain.Role;
import com.gpnu.crm.mapper.RoleMapper;
import com.gpnu.crm.query.QueryObject;
import com.gpnu.crm.service.IRoleService;

@Service
public class RoleServiceImpl implements IRoleService{

	 @Autowired
	  private RoleMapper roleMapper;
	  
	  public RoleServiceImpl() {}
	  
	  public void saveOrUpdate(Role entity, Long[] ids)
	  {
	    if (entity.getId() == null) {
	      roleMapper.insert(entity);
	    }
	    else {
	      roleMapper.deleteRelation(entity.getId());
	      roleMapper.updateByPrimaryKey(entity);
	    }
	    
	    if (ids != null) {
	      for (Long id : ids) {
	        roleMapper.insertRelation(entity.getId(), id);
	      }
	    }
	  }
	  
	  public void delete(Long id)
	  {
	    roleMapper.deleteRelation(id);
	    roleMapper.deleteByPrimaryKey(id);
	  }
	  
	  public Role get(Long id) {
	    return roleMapper.selectByPrimaryKey(id);
	  }
	  
	  public List<Role> list() {
	    return roleMapper.selectAll();
	  }
	  
	  public PageInfo<Role> query(QueryObject qo) {
	    List<Role> list = roleMapper.selectForList(qo);
	    return new PageInfo(list);
	  }

}
